import { Map} from "immutable";
import {UPDATE_PRODUCT_DETAIL} from '../actionTypes'
const defaultState = Map({
  productInfo: {
    showSkuSpecList: false,
    num:1,
    SkuSpecList:{},
    pic:'',
    name:'',
    tag:'',
    price:0,
    oldPrice:0,
    itemId:'1392026'
  },
  CartList:[],
  totalNum:0,
  
});
export default (state = defaultState, action) => {
  if (action.type === UPDATE_PRODUCT_DETAIL) {
    if(action.payload.keyArr.length===1&&action.payload.keyArr[0]==='CartList'){
      window.localStorage.setItem('CartList',JSON.stringify(action.payload.val))
    }
    return state.setIn(action.payload.keyArr,action.payload.val);
  } else if(action.type==='CHANGE_SHOW'){
    return state.setIn(['productInfo','showSkuSpecList'],action.payload)
  }else if(action.type==='CHANGE_NUM'){
    return state.setIn(['productInfo','num'],action.payload)
  }else if(action.type==="CHANGE_SKU_LIST"){
    return state.setIn(['productInfo','SkuSpecList'],action.payload)
  }else if(action.type==="SET_TOTAL_NUM"){
    return state.setIn(['totalNum'],action.payload)
  }
  else{
    return state
  }
}